package com.ecmaster.search;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import redis.clients.jedis.Jedis;

import java.util.*;

@Controller
@RequestMapping("/")
public class HelloController {

	private Jedis jedis =  new Jedis("127.0.0.1") ;

	@RequestMapping(method = RequestMethod.GET)
	public String printWelcome(ModelMap model) {
		model.addAttribute("message", "Search Demo v1.1");
		return "hello";
	}

	@RequestMapping(value = "/search_ajax",method = RequestMethod.GET)
	@ResponseBody
	public Set search_ajax(String q) {
		System.out.println("search q:"+q);
		return jedis.zrevrange(q, 0, -1);
	}

	@RequestMapping(value = "/search",method = RequestMethod.GET)
	public String search(String q) {
		return "hello";
	}
}